package com.ljw.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author lijunwei
 * @date 2025/5/21
 */
public class RuleDateUtil {

    public static final String dateString = "yyyy-MM-dd";
    public static final String spanTimeString = "yyyyMMddHHmmssSSS";
    public static final String dateTimeString = "yyyy-MM-dd HH:mm:ss";

    public static String datesToString(Date date) {
        SimpleDateFormat simple = new SimpleDateFormat(dateString);
        return simple.format(date);
    }

    public static String timeToStringByFormat(Date date, String format) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
            String parse = simpleDateFormat.format(date);
            return parse;
        } catch (Exception var4) {
            throw new RuntimeException("时间转换异常", var4);
        }
    }

    public static String getLocalDateTimeString() {
        SimpleDateFormat sdf = new SimpleDateFormat(spanTimeString);
        Date now = new Date();
        return sdf.format(now);
    }

    public static Date parseStrToDateFormat(String dateStr, String format) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        try {
            Date parse = simpleDateFormat.parse(dateStr);
            return parse;
        } catch (Exception e) {
            throw new RuntimeException("时间转换异常", e);
        }
    }


}

